System.register(["@angular/http", "ng2-layer", "@angular/core", "@angular/router", "@angular/forms"], function (exports_1, context_1) {
    "use strict";
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __metadata = (this && this.__metadata) || function (k, v) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
    };
    var __moduleName = context_1 && context_1.id;
    var http_1, ng2_layer_1, core_1, router_1, forms_1, BoxAddressComp, AddAddressComp, _a, _b;
    return {
        setters: [
            function (http_1_1) {
                http_1 = http_1_1;
            },
            function (ng2_layer_1_1) {
                ng2_layer_1 = ng2_layer_1_1;
            },
            function (core_1_1) {
                core_1 = core_1_1;
            },
            function (router_1_1) {
                router_1 = router_1_1;
            },
            function (forms_1_1) {
                forms_1 = forms_1_1;
            }
        ],
        execute: function () {
            BoxAddressComp = (function () {
                function BoxAddressComp(http, router, layer, parent) {
                    var _this = this;
                    this.http = http;
                    this.layer = layer;
                    this.parent = parent;
                    router.parent.params.subscribe(function (params) {
                        _this.boxId = params.id;
                        http.get({
                            search: {
                                m: "Admin",
                                c: "ApiBox",
                                a: "getBoxAddressConfig",
                                box_id: _this.boxId
                            }
                        }).then(function (data) {
                            _this.addresses = data.data.data;
                            _this.addresses.forEach(function (adr) {
                                adr.option = adr.option == 0 ? false : true;
                            });
                        });
                    });
                }
                BoxAddressComp.prototype.deleteAdr = function (adr) {
                    var _this = this;
                    var adrs = this.addresses.filter(function (i) {
                        return i !== adr;
                    });
                    this.saveAddress(adrs, function () {
                        _this.addresses = adrs;
                    });
                };
                BoxAddressComp.prototype.saveAddress = function (adrs, callBack) {
                    if (!adrs) {
                        adrs = this.addresses.slice();
                    }
                    adrs.forEach(function (adr) {
                        adr.option = adr.option ? 1 : 0;
                    });
                    this.http.post({
                        search: {
                            m: "Admin",
                            c: "ApiBox",
                            a: "setBoxOpenAddress"
                        },
                        body: {
                            is_address_open: "open",
                            address: JSON.stringify(adrs),
                            box_id: this.boxId
                        }
                    }).then(function (data) {
                        callBack ? callBack() : '';
                    });
                };
                BoxAddressComp.prototype.addAddress = function () {
                    var ly = this.layer.dialog({
                        title: "添加可送地址",
                        parent: this.parent,
                        dialogComponent: AddAddressComp,
                        imports: [forms_1.FormsModule],
                        data: { addresses: this.addresses, boxId: this.boxId, parent: this }
                    });
                };
                return BoxAddressComp;
            }());
            BoxAddressComp = __decorate([
                core_1.Component({
                    selector: '.box_address',
                    templateUrl: 'template/router/boxSetting/address.html'
                }),
                __metadata("design:paramtypes", [http_1.Http,
                    router_1.ActivatedRoute, typeof (_a = typeof ng2_layer_1.NgLayer !== "undefined" && ng2_layer_1.NgLayer) === "function" && _a || Object, core_1.ViewContainerRef])
            ], BoxAddressComp);
            exports_1("BoxAddressComp", BoxAddressComp);
            AddAddressComp = (function () {
                function AddAddressComp(ly, http) {
                    this.ly = ly;
                    this.http = http;
                }
                AddAddressComp.prototype.cancel = function () { this.ly.close(); };
                ;
                AddAddressComp.prototype.add = function () {
                    var _this = this;
                    var adrs = this.addresses;
                    adrs.push({
                        option: 1,
                        address: this.address
                    });
                    adrs.forEach(function (adr) {
                        adr.option = adr.option ? 1 : 0;
                    });
                    this.http.post({
                        search: {
                            m: "Admin",
                            c: "ApiBox",
                            a: "setBoxOpenAddress"
                        },
                        body: {
                            is_address_open: "open",
                            address: JSON.stringify(adrs),
                            box_id: this.boxId
                        }
                    }).then(function (data) {
                        _this.parent.addresses = adrs;
                        _this.ly.close();
                    });
                };
                return AddAddressComp;
            }());
            AddAddressComp = __decorate([
                core_1.Component({
                    templateUrl: "template/dialog/addAddress.html"
                }),
                __metadata("design:paramtypes", [typeof (_b = typeof ng2_layer_1.NgLayerRef !== "undefined" && ng2_layer_1.NgLayerRef) === "function" && _b || Object, http_1.Http])
            ], AddAddressComp);
        }
    };
});
